package com.cn.kabalifeuser.ui.my.activity;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.TextView;

import com.cn.kabalifeuser.R;
import com.cn.kabalifeuser.base.IBaseActivity;
import com.cn.kabalifeuser.config.LoginHelper;
import com.cn.kabalifeuser.ui.login.bean.MsgBean;
import com.cn.kabalifeuser.utils.LoggerUtils;
import com.cn.kabalifeuser.utils.RxToast;
import com.cn.kabalifeuser.utils.SoftHideKeyBoardUtil;
import com.cn.kabalifeuser.view.PhoneCode;
import com.cn.kabalifeuser.view.PhoneMainCode;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 项目：KaBaLifeUser
 * 包名：com.cn.kabalifeuser.ui.my.activity
 * 类名：UpPhoneCodeActivity
 * 创建时间：2020/11/10 11:23 AM
 * 创建人 @author： xiaolin
 * 描述 ：Todo...
 */
public class UpPhoneCodeActivity extends IBaseActivity<UpPhoneView, UpPhonePresenter> implements UpPhoneView {

    Bundle bundle;
    String phone;
    @BindView(R.id.tv_phone)
    TextView tvPhone;
    @BindView(R.id.et_phone_code)
    PhoneMainCode etPhoneCode;

    @Override
    protected UpPhonePresenter createPresenter() {
        return new UpPhonePresenter();
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_up_phone_code;
    }


    @Override
    public void initView(Bundle savedInstanceState) {
        super.initView(savedInstanceState);
        SoftHideKeyBoardUtil.assistActivity(this);
        setTitleBar("修改手机");
        bundle = getIntent().getExtras();
        phone = bundle.getString("phone");
        tvPhone.setText("已发送到：+" + phone);
        etPhoneCode.setOnInputListener(new PhoneMainCode.OnInputListener() {
            @Override
            public void onSucess(String code) {
                LoggerUtils.e("验证码:" + code);
//                hideKeyboard(etPhoneCode);
                //正常登錄
                mPresenter.onUpUserInfoPHoneData(LoginHelper.getLonginData().getResult(),
                        phone,
                        code);
            }

            @Override
            public void onInput() {

            }
        });

    }


    @Override
    public void onPhoneCodeSuccess(MsgBean bean) {

    }

    @Override
    public void onReLoggedIn(String msg) {
RxToast.error(msg);
LoginHelper.againGoToLoginActivity(getMe());
    }

    @Override
    public void onError(String msg) {

        RxToast.error(msg);
    }

    @Override
    public Context _getContext() {
        return getMe();
    }

    @Override
    public void onUpUserInfoSuccess(MsgBean bean) {

        RxToast.success(bean.getMsg());
        finish();
    }

}
